﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using BlueCrest.Sample.Data;
using NUnit.Framework;
using ProtoBuf;

namespace BlueCrest.Sample.Tests
{
    [TestFixture]
    public class ProtoBufTests
    {
        [Test]
        public void Serialize()
        {
            var author = GetSampleAuthor();

            using (var file = File.Create("person.bin"))
            {
                Serializer.Serialize(file, author);
            }
        }

        public static Author GetSampleAuthor()
        {
            var author = new Author
                             {
                                 FirstName = "Stephen",
                                 LastName = "King",
                                 
                                 Books = new List<Book>
                                             {
                                                 new Book
                                                     {
                                                         ISBN = "ISBN",
                                                         Price = 12.99,
                                                         PublishedOn = DateTime.Now,
                                                         Title = "Christine"
                                                     },
                                                 new Book
                                                     {
                                                         ISBN = "ISBN2",
                                                         Price = 14.99,
                                                         PublishedOn = DateTime.Now.AddDays(-5),
                                                         Title = "Doomsday"
                                                     }
                                             }
                             };
            return author;
        }

        [Test]
        public void Deserialize()
        {
            Author author;
            using (var file = File.OpenRead("person.bin"))
            {
                author = Serializer.Deserialize<Author>(file);
            }

            Assert.IsNotNull(author);
        }
    }
}
